home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-09-29 | 13.4 KB | 561 lines | [TEXT/KAHL] |
- #include <assert.h>
-
- #include <Windows.h>
- #include <QDOffscreen.h>
- #include <Memory.h>
- #include <Fonts.h>
- #include <Packages.h>
- #include <SegLoad.h>
- #include <ToolUtils.h>
- #include <TextEdit.h>
- #include <Files.h>
- #include <Palettes.h>
-
- #include <Retrace.h>
- #include <Devices.h>
- #include <Timer.h>
- #include <ColorPicker.h>
-
- #include "C_randomizer.h"
-
- #include "general.h"
- #include "port.h"
- #include "window.h"
- #include "depthchange.h"
- #include "fullscreen.h"
- #include "gworld.h"
- #include "scrolling_noise.h"
-
- #include "application.h"
-
- #include "stopwatch.h"
- #include "vretrace.h"
-
- typedef struct settings
- {
- short first_demo;
- short last_demo;
- short display_width;
- short display_height;
- short width;
- short height;
- short stripeSize;
- short speed;
- short speed_2;
- short freq;
- } settings;
-
- typedef void demoFunc( const settings &theSettings, fullscreen &full,
- const Rect &origRect, const Rect &destRect, long *num_millis, long *num_frames);
-
- demoFunc doTemporalTransparancy;
- demoFunc doHorizontalStripes;
- demoFunc doVerticalStripes;
- demoFunc doLSNRDemo;
- demoFunc doWGCheck1;
- demoFunc doWGCheck2;
-
- #define numFuncs 6
-
- demoFunc *theDemoFuncTable[ numFuncs] =
- {
- doTemporalTransparancy,
- doHorizontalStripes,
- doVerticalStripes,
- doLSNRDemo,
- doWGCheck1,
- doWGCheck2
- };
-
- #define max(x,y) ((x) > (y)) ? (x) : (y)
- #define min(x,y) ((x) > (y)) ? (y) : (x)
-
- void main()
- {
- application me;
-
- Handle theResource = Get1Resource( 'Cnfg', 128);
- settings theSettings;
-
- BlockMoveData( (settings *)*theResource, &theSettings, sizeof( settings));
-
- const int width = theSettings.width;
- const int height = theSettings.height;
- const int display_width = theSettings.display_width;
- const int display_height = theSettings.display_height;
-
- ReleaseResource( theResource);
-
- const int first_demo = max( 0, theSettings.first_demo);
- const int last_demo = min( (numFuncs - 1), theSettings.last_demo);
-
- long the_millies[ numFuncs];
- long the_frames[ numFuncs];
- long the_freqs[ numFuncs];
-
- {
- fullscreen full( 1);
- Rect fullRect;
- full.get_rect( &fullRect);
-
- const short vSize = fullRect.bottom - fullRect.top;
- const short hSize = fullRect.right - fullRect.left;
-
- const Rect origRect = {0, 0, height, width};
- Rect destRect;
- destRect.top = (vSize - display_height) / 2;
- destRect.left = (hSize - display_width ) / 2;
- destRect.bottom = destRect.top + display_height;
- destRect.right = destRect.left + display_width;
-
- for( int stimType = first_demo; stimType <= last_demo; stimType += 1)
- {
- long num_millis = 0;
- long num_frames = 0;
- full.cls_black();
- theDemoFuncTable[ stimType]( theSettings, full, origRect, destRect, &num_millis, &num_frames);
- const long millis_per_frame =
- (num_frames == 0) ? 0 : (2 * num_millis + num_frames) / (2 * num_frames);
-
- the_millies[ stimType] = num_millis;
- the_frames[ stimType] = num_frames;
- the_freqs[ stimType] = millis_per_frame;
-
- while( Button()){}
- }
- }
- window v( 300, 30 + 20 * numFuncs);
- v.use();
- TextFont( monaco);
- TextSize( 9);
- TextMode( srcCopy);
-
- MoveTo( 10, 10);
- DrawString( "\pframes");
-
- MoveTo( 110, 10);
- DrawString( "\pms");
-
- MoveTo( 210, 10);
- DrawString( "\pms/frame");
-
- short vPos = 30;
-
- for( int stimType = first_demo; stimType <= last_demo; stimType += 1)
- {
- Str31 string;
-
- MoveTo( 10, vPos);
- NumToString( the_frames[ stimType], string);
- DrawString( string);
-
- MoveTo( 110, vPos);
- if( the_millies[ stimType] > 0xFFFF)
- {
- DrawString( "\pOverflow in time counter");
- } else {
- NumToString( the_millies[ stimType], string);
- DrawString( string);
- }
- MoveTo( 210, vPos);
- NumToString( the_freqs[ stimType], string);
- DrawString( string);
-
- vPos += 20;
- }
- while( Button()){}
- while( !Button()){}
- while( Button()){}
- }
-
- void doTemporalTransparancy( const settings &theSettings, fullscreen &full,
- const Rect &origRect, const Rect &destRect, long *num_millis, long *num_frames)
- {
- const int width = theSettings.width;
- const int height = theSettings.height;
- const int speed = theSettings.speed;
- const int speed_2 = theSettings.speed_2;
- const int freq = theSettings.freq;
-
- scrolling_noise H_pixels( width, height, 1, speed, speed_2, full);
-
- scrolling_noise V_pixels( width, height, 1, speed_2, speed, full);
-
- vretrace it( freq);
- it.start();
-
- stopwatch omega;
- omega.start();
-
- while( !Button())
- {
- it.sync();
- full.copyfrom( H_pixels, origRect, destRect);
- H_pixels.step();
- *num_frames += 1;
-
- it.sync();
- full.copyfrom( V_pixels, origRect, destRect);
- V_pixels.step();
- *num_frames += 1;
- }
- *num_millis = (long)stopwatch::milliseconds( omega.stop());
- }
-
- void doHorizontalStripes( const settings &theSettings, fullscreen &full,
- const Rect &origRect, const Rect &destRect, long *num_millis, long *num_frames)
- {
- const int width = theSettings.width;
- const int height = theSettings.height;
- const int stripeSize = theSettings.stripeSize;
- const int speed = theSettings.speed;
- const int speed_2 = theSettings.speed_2;
- const int freq = theSettings.freq;
- //
- // fill stripes with random pixels:
- //
- const int numstripes = height / stripeSize;
-
- scrolling_noise toTheLeft( width, height / 2, 1, -speed_2, -speed, full);
- scrolling_noise toTheRight( width, height / 2, 1, speed_2, speed, full);
-
- const Rect stripeRect = {0, 0, stripeSize, width};
-
- gworld total( width, height, 1);
-
- vretrace it( freq);
- it.start();
-
- stopwatch omega;
- omega.start();
-
- while( !Button())
- {
- //
- // for every stripe, scroll it, scrolling in a new empty line,
- // and then copy it into the 'total' gworld.
- //
- Rect orig = stripeRect;
- Rect dest = stripeRect;
-
- toTheLeft.step();
- toTheRight.step();
-
- for( int i = 0; i < numstripes; i++)
- {
- if( (i & 1) == 1)
- {
- total.copyfrom( toTheLeft, orig, dest);
- OffsetRect( &orig, 0, stripeSize);
- } else {
- total.copyfrom( toTheRight, orig, dest);
- }
- OffsetRect( &dest, 0, stripeSize);
- }
- //
- // copy the result to the screen:
- //
- it.sync();
- full.copyfrom( total, origRect, destRect);
- *num_frames += 1;
- }
- *num_millis = (long)stopwatch::milliseconds( omega.stop());
- }
-
- void doVerticalStripes( const settings &theSettings, fullscreen &full,
- const Rect &origRect, const Rect &destRect, long *num_millis, long *num_frames)
- {
- const int width = theSettings.width;
- const int height = theSettings.height;
- const int stripeSize = theSettings.stripeSize;
- const int speed = theSettings.speed;
- const int speed_2 = theSettings.speed_2;
- const int freq = theSettings.freq;
- //
- // fill stripes with random pixels:
- //
- const int numstripes = width / stripeSize;
-
- scrolling_noise toTheTop( width / 2, height, 1, speed, speed_2, full);
- scrolling_noise toTheBottom( width / 2, height, 1, -speed, -speed_2, full);
-
- const Rect stripeRect = {0, 0, height, stripeSize};
-
- gworld total( width, height, 1);
-
- vretrace it( freq);
- it.start();
-
- stopwatch omega;
- omega.start();
-
- while( !Button())
- {
- //
- // for every stripe, scroll it, scrolling in a new empty line,
- // and then copy it into the 'total' gworld.
- //
- Rect orig = stripeRect;
- Rect dest = stripeRect;
-
- toTheTop.step();
- toTheBottom.step();
-
- for( int i = 0; i < numstripes; i++)
- {
- if( (i & 1) == 1)
- {
- total.copyfrom( toTheTop, orig, dest);
- OffsetRect( &orig, stripeSize, 0);
- } else {
- total.copyfrom( toTheBottom, orig, dest);
- }
- OffsetRect( &dest, stripeSize, 0);
- }
- //
- // copy the result to the screen:
- //
- it.sync();
- full.copyfrom( total, origRect, destRect);
- *num_frames += 1;
- }
- *num_millis = (long)stopwatch::milliseconds( omega.stop());
- }
-
- void doLSNRDemo( const settings &theSettings, fullscreen &full,
- const Rect &origRect, const Rect &destRect, long *num_millis, long *num_frames)
- {
- const int width = theSettings.width;
- const int height = theSettings.height;
- const int speed = theSettings.speed;
- const int speed_2 = theSettings.speed_2;
- const int freq = theSettings.freq;
- //
- // create the two one-bit worlds, a two-bit world
- // containing the noise-degraded signal, and a world
- // to put 'new noise' in.
- //
- gworld noiseWorld( width, height, 1);
- scrolling_noise signalWorld( width, height, 1, speed, speed_2);
-
- CTabHandle theColors = (CTabHandle)Get1Resource( 'clut', 128);
-
- fullscreen fullTwo( 2, theColors);
-
- gworld totalWorld( width, height, 2, fullTwo);
-
- vretrace it( freq);
- it.start();
-
- stopwatch omega;
- omega.start();
-
- Rect fullRect;
- fullTwo.get_rect( &fullRect);
-
- while( !Button())
- {
- //
- // shift signal to the right a column, filling space with new noise
- //
- signalWorld.step();
- //
- // generate new noise, and merge it with the signal:
- //
- noiseWorld.fill_random();
-
- totalWorld.two_bit_merge( signalWorld, noiseWorld);
- //
- // copy the result to the screen:
- //
- // it.sync();
- fullTwo.copyfrom( totalWorld, origRect, destRect);
- //
- // Adjust signal to noise ratio
- //
- // To get a LSNR of S we should solve for x from (Note: this formula is bogus!!!)
- //
- // (0x8000 + x) / (0x8000 - x) == S
- //
- // <=> x == 0x8000 * (S - 1) / (S + 1)
- //
- Point where;
- GetMouse( &where);
-
- LocalToGlobal( &where);
-
- if( PtInRect( where, &fullRect))
- {
- static const Rect largeRect = {0, 0, 32767, 32767};
- MapPt( &where, &fullRect, &largeRect);
- const unsigned short noise = 2 * ((unsigned short)where.h);
- const unsigned short signal = 0xFFFF - noise;
- const unsigned short both = signal + noise;
-
- ColorSpec newColors[ 4] =
- {
- {0, {0x0000, 0x0000, 0x0000}}, // black
- {1, {noise , noise , noise }},
- {2, {signal, signal, signal}},
- {3, {both , both , both }} // signal + noise
- };
- fullTwo.setentries( 0, 3, newColors);
- }
- *num_frames += 1;
- }
- *num_millis = (long)stopwatch::milliseconds( omega.stop());
- ReleaseResource( (Handle)theColors);
- }
-
- void doWGCheck1( const settings &theSettings, fullscreen &full,
- const Rect &origRect, const Rect &destRect, long *num_millis, long *num_frames)
- {
- const int width = theSettings.width;
- const int height = theSettings.height;
- const int stripeSize = theSettings.stripeSize;
- const int speed = theSettings.speed;
- const int speed_2 = theSettings.speed_2;
- const int freq = theSettings.freq;
-
- CTabHandle theColors = (CTabHandle)Get1Resource( 'clut', 128);
-
- fullscreen fullTwo( 2, theColors);
- fullTwo.cls_white();
-
- scrolling_noise signal( 4 * stripeSize, height, 1, speed, speed_2);
- gworld mask( 4 * stripeSize, height, 1);
- gworld total( 4 * stripeSize, height, 2, fullTwo);
-
- const Rect orig = {0, 0, height, 4 * stripeSize};
-
- const short destMid = (destRect.left + destRect.right) / 2;
- const Rect dest = {destRect.top, destMid - 2 * stripeSize, destRect.top + height, destMid + 2 * stripeSize};
-
- const Rect topR = {0, 0, height / 2, 4 * stripeSize};
- const Rect botR = {height / 2, 0, height, 4 * stripeSize};
-
- const Rect topR_half = {0, stripeSize, height / 2, 3 * stripeSize};
- const Rect botR_half = {height / 2, stripeSize, height, 3 * stripeSize};
-
- mask.use();
-
- PaintRect( &topR);
- EraseRect( &topR_half);
-
- EraseRect( &botR);
- PaintRect( &botR_half);
-
- fullTwo.use(); // prevents a bug in vretrace.cp to crash the Mac
- vretrace it( freq);
- it.start();
-
- stopwatch omega;
- omega.start();
-
- Rect fullRect;
- fullTwo.get_rect( &fullRect);
-
- const unsigned short grys = 0x8000;
- ColorSpec newColors[ 4] =
- {
- {0, {0, 0, 0}},
- {1, {0, 0, 0}},
- {2, {0, 0, 0}}, // = entire screen
- {3, {0, 0, 0}}
- };
- const HSVColor grysHSV = {0, 0, grys};
-
- HSV2RGB( &grysHSV, &newColors[ 0].rgb);
- HSV2RGB( &grysHSV, &newColors[ 2].rgb);
-
- while( !Button())
- {
- signal.step();
-
- total.two_bit_merge( signal, mask);
- it.sync();
- fullTwo.copyfrom( total, orig, dest);
- //
- // Adjust signal strength:
- //
- Point where;
- GetMouse( &where);
-
- LocalToGlobal( &where);
-
- if( PtInRect( where, &fullRect))
- {
- static const Rect largeRect = {0, 0, 32767, 32767};
- MapPt( &where, &fullRect, &largeRect);
- const unsigned short dark = ((unsigned short)where.h);
- const unsigned short light = 0xFFFF - dark;
-
- const HSVColor darkHSV = {0, 0, dark};
- const HSVColor lightHSV = {0, 0, light};
-
- HSV2RGB( &darkHSV, &newColors[ 3].rgb);
- HSV2RGB( &lightHSV, &newColors[ 1].rgb);
-
- fullTwo.setentries( 0, 3, newColors);
- }
- *num_frames += 1;
- }
- *num_millis = (long)stopwatch::milliseconds( omega.stop());
- ReleaseResource( (Handle)theColors);
- }
-
- void doWGCheck2( const settings &theSettings, fullscreen &full,
- const Rect &origRect, const Rect &destRect, long *num_millis, long *num_frames)
- {
- const int width = theSettings.width;
- const int height = theSettings.height;
- const int stripeSize = theSettings.stripeSize;
- const int speed = theSettings.speed;
- const int speed_2 = theSettings.speed_2;
- const int freq = theSettings.freq;
- //
- // fill stripes with random pixels:
- //
- const int numstripes = width / stripeSize;
-
- scrolling_noise toTheLeft( width, height, 1, speed, speed_2, full);
-
- const Rect stripeRect = {0, 0, height, stripeSize};
-
- gworld total( width, height, 1);
-
- vretrace it( freq);
- it.start();
-
- stopwatch omega;
- omega.start();
-
- while( !Button())
- {
- //
- // for every stripe, scroll it, scrolling in a new empty line,
- // and then copy it into the 'total' gworld.
- //
- Rect orig = stripeRect;
- Rect dest = stripeRect;
-
- OffsetRect( &dest, width - stripeSize, 0);
-
- toTheLeft.step();
-
- for( int i = 0; i < numstripes; i++)
- {
- total.copyfrom( toTheLeft, orig, dest);
- OffsetRect( &orig, stripeSize, 0);
- OffsetRect( &dest, -stripeSize, 0);
- }
- //
- // copy the result to the screen:
- //
- it.sync();
- full.copyfrom( total, origRect, destRect);
- *num_frames += 1;
- }
- *num_millis = (long)stopwatch::milliseconds( omega.stop());
- }
-